﻿using System;
using System.Collections.Generic;
using System.Text;
using WCFContracts;
using System.Runtime.Remoting.Channels.Tcp;
using Pub.Lib;


namespace Pub
{

    public enum DataAccessType
    {
        CS,
        WCF,
        REMOTING
    }

    public class PubVar : MarshalByRefObject
    {

        public PubVar()
        {
            //   Console.Write("构造方法 ");
        }

        public class sysUser
        {
            private string _cUserCode; //编码  
            private string _cUserName; //姓名  
            private string _cUserPWD; //密码  
            private Boolean _bAdmin = false; //是否管理员 
            private Boolean _bRead = false; //读权限
            private Boolean _bWrite = false; //写权限
            private string _cUnique = "0"; // 唯一值


            //创建sysUser对象  
            public sysUser()
            {
            }

            /// <summary>
            ///编码 
            /// </summary>
            public string cUserCode
            {
                get { return _cUserCode; }
                set { _cUserCode = value; }
            }


            /// <summary>
            /// 名称
            /// </summary>
            public string cUserName
            {
                get { return _cUserName; }
                set { _cUserName = value; }
            }

            /// <summary>
            /// 密码
            /// </summary>
            public string cUserPWD
            {
                get { return _cUserPWD; }
                set { _cUserPWD = value; }
            }

            /// <summary>
            /// 读权限
            /// </summary>
            public Boolean bRead
            {
                get { return (bWrite || _bRead); }
                set { _bRead = value; }
            }

            /// <summary>
            /// 写权限
            /// </summary>
            public Boolean bWrite
            {
                get { return (bAdmin || _bWrite); }
                set { _bWrite = value; }
            }

            /// <summary>
            /// 是否管理员
            /// </summary>
            public Boolean bAdmin
            {
                get { return _bAdmin; }
                set { _bAdmin = value; }
            }


            /// <summary>
            /// 唯一值
            /// </summary>
            public string cUnique
            {
                get { return _cUnique; }
                set { _cUnique = value; }
            }


        }


  
        public class Corp
        {

            private string _cCorpNo;
            private string _cCorpAbbName;
            private string _cCorpName;
            private string _cPreCode;
            private string _cDrCode;
            private string _cCrCode;

            //创建Corp对象  
            public Corp()
            {
            }

            /// <summary>
            /// 编号
            /// </summary>
            public string cCorpNo
            {
                get { return _cCorpNo; }
                set { _cCorpNo = value; }
            }

            /// <summary>
            /// 简称
            /// </summary>
            public string cCorpAbbName
            {
                get { return _cCorpAbbName; }
                set { _cCorpAbbName = value; }
            }

            /// <summary>
            /// 名称
            /// </summary>
            public string cCorpName
            {
                get { return _cCorpName; }
                set { _cCorpName = value; }
            }

            /// <summary>
            /// 前缀
            /// </summary>
            public string cPreCode
            {
                get { return _cPreCode; }
                set { _cPreCode = value; }
            }

            /// <summary>
            /// 借方科目
            /// </summary>
            public string cDrCode
            {
                get { return _cDrCode; }
                set { _cDrCode = value; }
            }

            /// <summary>
            /// 贷方科目
            /// </summary>
            public string cCrCode
            {
                get { return _cCrCode; }
                set { _cCrCode = value; }
            }
        }

        //系统调试变量
        public static Boolean SysUpdateSQL = false;

        public static string ConnMain = "HT";
        public static string Domain = "DW";

        //登录用户信息
        public static sysUser NowUser = new sysUser();

        //帐套信息
        public static Corp NowCorp = new Corp();

        //当前服务地址
        public static string SysServerURL = "";

        //当前Listen地址,WCF使用
        public static string SysListenURL = "";


        public static string strDBAccess = "DBAccess";
        public static string strSysUser = "SysUser";


        public static Dictionary<string, object> DicConn = new Dictionary<string, object>();

        //存放用户校验
        public static Dictionary<string, DateTime> DicLoginUser = new Dictionary<string, DateTime>();

        //系统分隔符
        public static string SysSplit = "<@:>";

        //系统用户代码,默认值为SYSTEM
        public static string SysArrAuth = "SYSTEM" + SysSplit + string.Format("{0:yyyyMMdd}", System.DateTime.Now) + SysSplit + Tools.SysTools.getGUID();

        public static DataAccessType SysDAT = DataAccessType.CS;
        public static string SysDATName = "C/S";

        //Remoting 认证域
        public static string SysSecure_Domain = string.Empty;

        //Remoting 认证域用户名
        public static string SysSecure_Username = string.Empty;

        //Remoting 认证域用户密码
        public static string SysSecure_Password = string.Empty;


        public static TcpChannel MyChannle;

        public static DBAccess objdb;
        public static SysUser objsysUser;

        public static ICalculator WcfProxy;


        public static string LogFile = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, string.Format("Log_{0:yyyyMMdd}.Txt", System.DateTime.Now));
        public static string UserXml = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, @"Xml\UserSet.xml");
        public static string SysSetXml = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, @"Xml\SysSet.xml");

        //当前服务地址列表
        public static string SysServerUrlList = Pub.Tools.XmlTools.GetServiceURLList(PubVar.SysSetXml);

        public static void GetSYSDAT()
        {
            string strDataAccessType = Pub.Tools.XmlTools.Read(PubVar.SysSetXml, "SysSet/DataAccessType");
            switch (strDataAccessType.ToUpper())
            {
                case "CS":
                    {
                        PubVar.SysDAT = DataAccessType.CS;
                        break;
                    }
                case "REMOTING":
                    {
                        PubVar.SysDAT = DataAccessType.REMOTING;
                        break;
                    }

                case "WCF":
                    {
                        PubVar.SysDAT = DataAccessType.WCF;
                        break;
                    }
            }
        }


    }
}
